Memory may be categorized into read-only memory (e.g., flash memory) and random-access memory. Flash memory reclaim may be used to collect invalid data (or unused data) from a flash memory and return the flash memory to a suitable condition for use. Flash memory reclaim may be categorized into foreground reclaim and background reclaim.
Foreground reclaim may be triggered by a file operation related to the flash memory. Time consumed for the foreground reclaim is aware by an application (e.g., user application or an operating system) that may initiate the file operation. Background reclaim may not be triggered by the file operation. Time consumed for the background reclaim is unaware by the application that may initiate the file operation. In some instances, the background reclaim may occur automatically and regularly (or periodically).
FIG. 1 illustrates an embodiment of a conventional foreground reclaim method. In block 101, a file operation related to a flash memory is determined. Examples of the file operation may comprise writing a file to the flash memory, updating the file stored on the flash memory, and deleting the file from the flash memory. In block 102, it may be determined whether a foreground reclaim is needed for the file operation. Some circumstances related to the file operation may trigger the foreground reclaim, e.g., not enough space for the file operation.
In response that the foreground reclaim is needed, a flash memory block may be selected from a plurality of flash memory block as a reclaim memory block in block 103; the reclaim memory block may be searched for valid data in block 104, and the valid data may be copied from the reclaim memory block to a spare memory block if it is found from the reclaim memory block in block 105. For some instances, the spare memory block may be a flash memory block reserved for a flash memory reclaim.
Then, in block 106, the reclaim memory block may be erased so that it may become a new spare memory block reserved for a next memory reclaim. In block 107, the file operation may be performed on the flash memory, for example, on the spare memory block.